﻿using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Drawing;

namespace IAD2
{
    class Program
    {
        static int epocNumber = 1000;
        static void Main(string[] args)
        {
            //-----DANE TRENINGOWE-----
            Neuron center = new Neuron(0, 0);
            TrianglePoints a = new TrianglePoints(center, 3f, 50);
            List<Neuron> trenning = a.getPoints();
            center = new Neuron(3, 3);
            a = new TrianglePoints(center, 3f, 50);
            trenning.AddRange(a.getPoints());

            KohTests();

            //NeuronGasTests();

          
            Console.WriteLine("GIT");
            Console.ReadKey();
        }

        public static void KohTests()
        {
            Neuron center = new Neuron(0, 0);
            TrianglePoints a = new TrianglePoints(center, 3f, 50);
            List<Neuron> trenning = a.getPoints();
            center = new Neuron(3, 3);
            a = new TrianglePoints(center, 3f, 50);
            trenning.AddRange(a.getPoints());
            Neuron xRange = new Neuron(-5, 5);
            Neuron yRange = new Neuron(-5, 5);
            RandomPoints b = new RandomPoints(xRange, yRange, 10);

            double[] nTab = { 0.1, 0.5, 1, 1.5, 2, 2.5, 3.0};
            double[] neighbourTab = { 0.1, 0.2, 0.5, 1, 1.3, 2 };
            int[] sleepTab = { 0, 1, 2, 5, 10 };

            StreamWriter sw = File.CreateText("Koh");
            foreach (double n in nTab)
            {
                       
                        Network net = new Network(b.getPoints());

                        Kohonen algorithm = new Kohonen(net, trenning, n, neighbourTab.ElementAt(1), true,sleepTab.ElementAt(1));
                        algorithm.action(epocNumber);
                        sw.WriteLine(algorithm.getResult());
                        Console.Write(".");
            }
            sw.WriteLine();
                
            foreach (double neigh in neighbourTab)
            {
                       
                        Network net = new Network(b.getPoints());

                        Kohonen algorithm = new Kohonen(net, trenning, nTab.ElementAt(1), neigh, true,sleepTab.ElementAt(1));
                        algorithm.action(epocNumber);
                        sw.WriteLine(algorithm.getResult());
                        Console.Write(".");
            }
            sw.WriteLine();


            foreach (int sleep in sleepTab)
            {
                //-----Neurony-----
                
                Network net = new Network(b.getPoints());

                Kohonen algorithm = new Kohonen(net, trenning, nTab.ElementAt(1), neighbourTab.ElementAt(1), true, sleep);
                algorithm.action(epocNumber);
                sw.WriteLine(algorithm.getResult());
                Console.Write(".");
            }
            Console.WriteLine();

            sw.Close();

        }

        public static void NeuronGasTests()
        {
            Neuron center = new Neuron(0, 0);
            TrianglePoints a = new TrianglePoints(center, 3f, 50);
            List<Neuron> trenning = a.getPoints();
            center = new Neuron(3, 3);
            a = new TrianglePoints(center, 3f, 50);
            trenning.AddRange(a.getPoints());

            double[] nTab = { 0.1, 0.5, 1 };
            double[] maxRangeTab = { 0.2, 0.7, 2 };
            int[] sleepTab = { 0, 2, 5 };

            StreamWriter sw = File.CreateText("Gas");
            foreach (double n in nTab)
            {
                Neuron xRange = new Neuron(-5, 5);
                Neuron yRange = new Neuron(-5, 5);
                RandomPoints b = new RandomPoints(xRange, yRange, 10);
                Network net = new Network(b.getPoints());

                NeuronGas algorithm = new NeuronGas(net, trenning, n, maxRangeTab.ElementAt(1), 0.001, sleepTab.ElementAt(1));
                algorithm.action(epocNumber);
                sw.WriteLine(algorithm.getResult());
                Console.Write(".");
            }
            sw.WriteLine();

            foreach (double neigh in maxRangeTab)
            {
                Neuron xRange = new Neuron(-5, 5);
                Neuron yRange = new Neuron(-5, 5);
                RandomPoints b = new RandomPoints(xRange, yRange, 10);
                Network net = new Network(b.getPoints());

                NeuronGas algorithm = new NeuronGas(net, trenning, nTab.ElementAt(1), neigh, 0.001, sleepTab.ElementAt(1));
                algorithm.action(epocNumber);
                sw.WriteLine(algorithm.getResult());
                Console.Write(".");
            }
            sw.WriteLine();


            foreach (int sleep in sleepTab)
            {
                //-----Neurony-----
                Neuron xRange = new Neuron(-5, 5);
                Neuron yRange = new Neuron(-5, 5);
                RandomPoints b = new RandomPoints(xRange, yRange, 10);
                Network net = new Network(b.getPoints());

                NeuronGas algorithm = new NeuronGas(net, trenning, nTab.ElementAt(1), maxRangeTab.ElementAt(1), 0.001, sleep);
                algorithm.action(epocNumber);
                sw.WriteLine(algorithm.getResult());
                Console.Write(".");
            }
            Console.WriteLine();
            sw.Close();
                


        }
    }
}
